/*
 * @Author: 码上talk|RC
 * @Date: 2020-06-09 23:23:29
 * @LastEditTime: 2020-09-27 16:47:23
 * @LastEditors: 码上talk|RC
 * @Description: 
 * @FilePath: /tacomall-merchant/src/store/user/actions.js
 * @Just do what I think it is right
 */
import * as types from './mutation-types'
import api from '@/api'
import { session } from '@/libs/session'

export const actions = {
    getUserInfo({ commit }) {
        return new Promise((resolve) => {
            api.user.info().then(res => {
                if (res.status) {
                    commit(types.SET_PROFILE, res.data)
                    resolve()
                }
            })
        })
    },
    logout({ commit }) {
        return new Promise((resolve) => {
            api.user.info().then(res => {
                if (res.status) {
                    session.exit()
                    commit(types.SET_PROFILE, {})
                    commit('setIsLogin', false, { root: true })
                    resolve()
                }
            })
        })
    }
}
